package com.adv.netWork01.downloadServer;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class DownloadClient {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		Socket s = new Socket("localhost", 9999);
		System.out.println("-----------客户端-------------");
		InputStream in = s.getInputStream();// 读入服务器提示
		OutputStream out = s.getOutputStream();// 写出要查的文件名
		BufferedReader br = new BufferedReader(new InputStreamReader(in));// 读入服务器提示
		PrintWriter pw = new PrintWriter(out);// 写出要查的文件名
		String reply = br.readLine();// 读入服务器提示
		System.out.println("服务器说:" + reply);// 读入服务器提示
		System.out.print("请输入:");
		String str = input.next();
		pw.println(str);// 写出要查的文件名
		pw.flush();
		// 读入要查的文件
		InputStream is = new BufferedInputStream(in);
		OutputStream op = new BufferedOutputStream(new FileOutputStream(new File("/Users/zhaoyang/Desktop/str")));
		byte[] b = new byte[1024];
		int read;
		while ((read = is.read(b)) != -1) {
			op.write(b, 0, read);
		}
		op.flush();
		op.close();
		is.close();
	}

}
